import 'package:flutter/material.dart';
import 'pages/tabs/Tabs.dart';
// import 'routers/router.dart';
import 'package:flutter/rendering.dart';
import 'pages/test/Search.dart';
import './pages/tabs/ProductList.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:io'; // 设置状态栏背景及颜色---
import 'package:flutter/services.dart'; // 设置状态栏背景及颜色---

void main() {
  //设置debugPaintSizeEnabled为true来更直观的调试布局问题
  // debugPaintSizeEnabled = true;
  if (Platform.isAndroid) {
    // 设置状态栏背景及颜色---
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    // SystemChrome.setEnabledSystemUIOverlays([]); //隐藏状态栏
  }
  runApp(MyApp());
}

// 输入stf  有状态组件
// stss 无状态组件
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final Map<String, WidgetBuilder> routes = {
    '/': (context) => Tabs(),
    '/search': (context) => SearchPage(),
    '/productList': (context, {arguments}) =>
        ProductListPage(arguments: arguments)
  };

  Route<dynamic> _onGenerateRoute(RouteSettings settings) {
    //   return MaterialPageRoute(builder: (context) {
    // 如果访问的路由页需要登录，但当前未登录，则直接返回登录页路由，
    // 引导用户登录；其它情况则正常打开路由。
    // 统一处理
    // })
    final String? name = settings.name;
    final Function pageContentBuilder = routes[name] as Function;
    print('到1');
    if (settings.arguments != null) {
      print('到2');
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      print('到3');
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }

  @override
  Widget build(BuildContext context) {
    // return MaterialApp(
    //   // home: Tabs()
    //   initialRoute: '/',
    //   onGenerateRoute: _onGenerateRoute,
    // );
    return ScreenUtilInit(
      designSize: Size(360, 690),
      builder: () => MaterialApp(
        // home: Tabs()
        initialRoute: '/',
        onGenerateRoute: _onGenerateRoute,
      ),
    );
  }
}
